package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.IShoppingCarService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.service.ApiListing;

import javax.annotation.Resource;
import java.util.List;

/**
 * @BelongsProject: sky-take-out
 * @Author: XieMingHui
 * @CreateTime: 2023-11-27  18:13
 * @Description: 购物车接口
 * @Version: 1.0
 */
@RestController
@Slf4j
@Api(value = "购物车接口层")
@RequestMapping("/user/shoppingCart")
public class ShoppingCarController {
    @Resource
    private IShoppingCarService iShoppingCarService;
    /**
     * 添加商品到购物车
     * @author: XieMingHui
     * @param: [shoppingCartDTO]
     * @return: com.sky.result.Result<java.lang.String>
     **/
    @PostMapping("/add")
    public Result<String> addCar(@RequestBody ShoppingCartDTO shoppingCartDTO){
        return iShoppingCarService.addCar(shoppingCartDTO);
    }
    /**
     * 查询购物车
     * @author: XieMingHui
     * @param: []
     * @return: com.sky.result.Result<java.util.List<com.sky.entity.ShoppingCart>>
     **/
    @GetMapping("/list")
    public Result<List<ShoppingCart>> findCar(){
        return iShoppingCarService.findCar();
    }
    /**
     * 在购物车中删除商品
     * @author: XieMingHui
     * @param: [shoppingCartDTO]
     * @return: com.sky.result.Result<java.lang.String>
     **/
    @PostMapping("/sub")
    public Result<String> subCar(@RequestBody ShoppingCartDTO shoppingCartDTO){
        return iShoppingCarService.subCar(shoppingCartDTO);
    }
    /**
     * 清空购物车
     * @author: XieMingHui
     * @param: []
     * @return: com.sky.result.Result<java.lang.String>
     **/
    @DeleteMapping("/clean")
    public Result<String> cleanCar(){
        return iShoppingCarService.cleanCar();
    }

}
